package com.nettest.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.nettest.entity.system.Menu;
import com.nettest.pojo.AccordionVo;
import com.nettest.service.system.MenuService;

@Results({@Result(name = "success",location = "/index.jsp") })
public class IndexAction extends BaseJsonAction {

	private static final long serialVersionUID = -6392900428067353983L;
	@Autowired
	private MenuService menuService;
	private List<AccordionVo> accordions;
	private String homePage;
	public String execute() throws Exception {
		List<Menu> topMenu = menuService.getTopMenu(null);
		AccordionVo accordion = null;
		accordions = new ArrayList<AccordionVo>();
		for (Menu menu : topMenu) {
			accordion = new AccordionVo();
			accordion.setId(menu.getMenuId());
			accordion.setText(menu.getMenuName());
			accordion.setIconCls("icon-save");
			List<Menu> subMenus = menuService.getSubMenu(menu.getMenuId());
			String content = "<ul class=\"easyui-tree\" data-options=\"fit:true\">";
			for (Menu subMenu : subMenus) {
				content+="<li><div onclick=\"loadPage(\\'"+ subMenu.getMenuName() +"\\',\\'" + subMenu.getMenuAction() + "\\')\">"
					+ subMenu.getMenuName() + "</div></li>";
			}
			content+="</ul>";
			accordion.setContent(content);
			accordions.add(accordion);
		}
		
        return SUCCESS;
    }
	
	public List<AccordionVo> getAccordions() {
		return accordions;
	}

	public void setAccordions(List<AccordionVo> accordions) {
		this.accordions = accordions;
	}

	public String getHomePage() {
		return homePage;
	}
	public void setHomePage(String homePage) {
		this.homePage = homePage;
	}
}